package ru.ifmo.diplom.kirilchuk.coders.util;

/**
 * Package utility class for converting integers to bytes and back again in a
 * uniform manner.
 * 
 * @author <a href="http://www.colloquial.com/carp/">Bob Carpenter</a>
 * @version 1.1
 * @since 1.1
 */
public final class Converter {

	/**
	 * Returns byte coded by the specified integer.
	 * 
	 * @param i Integer to convert to a byte.
	 * @return Byte coded by the specified integer.
	 */
	public static byte integerToByte(int i) {
		return (byte) (i - 128);
	}

	/**
	 * Returns integer code for the specified byte.
	 * 
	 * @param b Byte to code as an integer.
	 * @return Integer code for the specified byte.
	 */
	public static int byteToInteger(byte b) {
		return 128 + (int) b;
	}

}
